package zyh.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;

//@WebFilter(filterName = "log",urlPatterns = {"/*"})
public class LogFilter implements Filter{
    private FilterConfig config;
    public void init(FilterConfig config) throws ServletException {
        this.config=config;
    }
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        ServletContext context=this.config.getServletContext();
        long before=System.currentTimeMillis();
        System.out.println("开始过滤写日志...时间："+new Date());
        HttpServletRequest hrequest=(HttpServletRequest)servletRequest;
        System.out.println("Filter stop url："+hrequest.getServletPath());
        filterChain.doFilter(servletRequest,servletResponse);
        long after=System.currentTimeMillis();
        System.out.println("ending");
        System.out.println("request "+hrequest.getRequestURI()+"   time："+(after-before));
//          System.out.println("LoginFilter de doFilter() run---req");
//          filterChain.doFilter(servletRequest,servletResponse);
//          System.out.println("LoginFilter de doFilter() run---resp");
    }
    public void destroy() {
        this.config=null;
    }
}
